﻿using System;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading;

namespace Event.ReactiveProgrammingConsole
{
    public class SimpleUsing
    {
       public static void WriteSequence()
       {
           Console.WriteLine("Thread {0}",Thread.CurrentThread.ManagedThreadId);
           var sequence = Enumerable.Range(1, 10);
           var observableSequence = sequence.ToObservable();
           observableSequence.Subscribe(i=>Console.WriteLine("{0} in thread {1}",i,Thread.CurrentThread.ManagedThreadId), () => Console.WriteLine("finished"));
       }

       public static void WriteSequenceUsingObserverPatten()
       {
           Console.WriteLine("Thread {0}", Thread.CurrentThread.ManagedThreadId);
           var sequence = Enumerable.Range(1, 10);
           var observableSequence = sequence.ToObservable();
           var observer =Observer.Create<int>(i => Console.WriteLine("{0} in thread {1}", i, Thread.CurrentThread.ManagedThreadId),() => Console.WriteLine("finished"));
           observableSequence.Subscribe(observer);
       }
    }
}